//
//  CustomerContractViewController.m
//  EPBPro
//
//  Created by wucha on 2018/6/27.
//  Copyright © 2018年 fc. All rights reserved.
//

#import "CustomerContractViewController.h"
#import "HttpContractAction.h"
#import "ContractActionInfo.h"
#import "CustomerContractViewCell.h"
#import "CustomerContractInfo.h"
#import "CustomerContractDetailViewController.h"

@interface CustomerContractViewController ()
@property (nonatomic,strong) NSArray *listArray;

@end

@implementation CustomerContractViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.titleName = @"客户合同";
    self.tableView.separatorStyle = 0;
    ContractActionInfo *contractActionInfo = [[ContractActionInfo alloc] init];
    contractActionInfo.offset = @"0";
    contractActionInfo.limit = @"10";
    [HttpContractAction postCustomerContractList:contractActionInfo block:^(id result, NSError *error) {
        if (!error) {
            self.listArray = result;
            [self.tableView reloadData];
        }
    }];
}

#pragma mark - Table view data 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return self.listArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    CustomerContractViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[CustomerContractViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    // Configure the cell...
    CustomerContractInfo *merchantContractInfo = self.listArray[indexPath.row];
    [cell setCustomerContractCell:merchantContractInfo];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    CustomerContractInfo *customerContractInfo = self.listArray[indexPath.row];
    CustomerContractDetailViewController *customerContractDetailViewController = [[CustomerContractDetailViewController alloc] initWithCustomerContract:customerContractInfo];
    [self.navigationController pushViewController:customerContractDetailViewController animated:YES];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 120;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
